package com.evan.designpatterns.strategy.refactor;


/**
 * @author :liujiapeng01
 * @date :2019-03-18 09:31
 **/
public enum OperationFactory {


    /**
     * 删除
     */
    delete("delete", new DeleteOperation()),
    /**
     * 合并
     */
    merge("merge", new MergeOperation());

    private String operationName;
    private Operation operation;


    OperationFactory(String operationName, Operation operation) {
        this.operationName = operationName;
        this.operation = operation;
    }


    public static Operation getOperation(String name) {
        OperationFactory[] factories = OperationFactory.values();
        Operation realFactory = null;

        for (OperationFactory factory : factories) {
            if (factory.operationName.equals(name)) {
                realFactory = factory.operation;
                break;
            }
        }
        return realFactory;


    }


}
